package com.apes.scm.masterdata.enumeration.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 标签
 * Created by lishikun on 2021/1/25 13:54
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = Tag.CONST_TABLE_NAME)
public class Tag extends BaseModel {
    public static final String CONST_TABLE_NAME = "mas_tag";

    @Id
    @Column(name = "id", length = 16)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "标签表")
    @Comment("编码")
    private String id;  //编码

    @NotNull
    @Column(name = "name")
    @Comment("标签名称")
    private String name;

    @Column(name = "remark")
    @Comment("备注")
    private String remark;

    @Column(name = "base_tag", nullable = false,columnDefinition = "number(1,0) default 0")
    @Comment("基础标签")
    private Boolean baseTag = false;

    @NotNull
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="enumeration_id", referencedColumnName="id")
    @Comment("标签维度")
    private EnumerationType enumerationType; //标签维度

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    private boolean valid = false; //有效

}
